<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of welcome
 *
 * @author Obi
 */
class Admin_konten_menu extends MY_Controller {

    function __construct() {
        parent::__construct();

        $cek_admin = $this->session->userdata('cek_admin');
        if (!$cek_admin)
            redirect("admin");
        $this->mkonten_menu = new M_konten_menu();
    }

    function index() {

        $data['title'] = 'Data Konten Menu';
        $data['list'] = $this->mkonten_menu->get();
        $data['isi'] = 'isi';
        $this->load->view('template_admin', $data);
    }

    function tambah() {


//        $link = "http" . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "") . "://";
//        $server = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
//        $base_urls = $link . $server;
        $base_urls = preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])) . '/';

        echo $base_urls;
        
        
        
        $data['title'] = 'Tambah Data Konten Menu';

        $data['id_konten_menu'] = "";
        $data['nama_konten_menu'] = "";
        $data['isi_konten_menu'] = "";
        $data['status'] = "1";

        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function edit($id = NULL) {

        $data['title'] = 'Ubah Data Konten Informasi';

        $dt = $this->mkonten_menu->where("id_konten_menu = '$id'")->get();

        $data['id_konten_menu'] = $dt->id_konten_menu;
        $data['nama_konten_menu'] = $dt->nama_konten_menu;
        $data['isi_konten_menu'] = $dt->isi_konten_menu;
        $data['status'] = $dt->status;


        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function delete($id) {
        $this->mkonten_menu->delete($id);
        redirect("admin_konten_menu");
    }

    function simpan() {
        $id = $this->input->post('id_konten_menu');

        $data = array(
            'nama_konten_menu' => $this->input->post('nama_konten_menu'),
            'isi_konten_menu' => $this->input->post('isi_konten_menu'),
            'status' => $this->input->post('status')
        );

        if ($id == "") {
            $this->mkonten_menu->insert($data);
        } else {
            $this->mkonten_menu->update($data, $id);
        }

        redirect("admin_konten_menu");
    }

}

?>
